#!/bin/sh

# builder.sh - Build everything and run all the tests

echo $LD_LIBRARY_PATH | egrep "/opt/bitnami/common" > /dev/null
if [ $? -ne 0 ] ; then
PATH="/opt/bitnami/memcached/bin:/opt/bitnami/perl/bin:/opt/bitnami/git/bin:/opt
/bitnami/nginx/sbin:/opt/bitnami/sphinx/bin:/opt/bitnami/sqlite/bin:/opt/bitnami
/php/bin:/opt/bitnami/mysql/bin:/opt/bitnami/apache2/bin:/opt/bitnami/subversion
/bin:/opt/bitnami/ruby/bin:/opt/bitnami/common/bin:$PATH"
export PATH
LD_LIBRARY_PATH="/opt/bitnami/ruby/lib/ruby/gems/1.8/gems/passenger-2.2.11/lib:/
opt/bitnami/memcached/lib:/opt/bitnami/perl/lib:/opt/bitnami/git/lib:/opt/bitnam
i/nginx/lib:/opt/bitnami/sqlite/lib:/opt/bitnami/mysql/lib:/opt/bitnami/apache2/
lib:/opt/bitnami/subversion/lib:/opt/bitnami/ruby/lib:/opt/bitnami/common/lib:$L
D_LIBRARY_PATH"
export LD_LIBRARY_PATH
fi

# Run android tests
echo "Building android"
cd android
android update project --path .
cd Robotium/test
android update test-project -p . -m ../..
ant run-tests
i=$?
echo $i

cd ../../..

# Run rails tests
echo "Building rails"
cd rails
rake db:migrate
rake
i=`expr $i + $?`
echo $i

if [ $i -eq 0 ] ; then 
  cap deploy:migrations
fi

# Return result
echo $i
exit $i
